<?php

namespace App\Admin\Requests;

use App\Admin\Models\Demo;
use App\Admin\Models\SystemModel;
use Illuminate\Support\Arr;

class DemoRequest extends FormRequest
{
    public function rules(SystemModel $systemModel, Demo $demo)
    {
        $demo = app(Demo::class);
        $rules = $systemModel->formValidationRules($demo->getTable());
        $keys = $this->keys();
        if ($this->isMethod('get')) {
            $rules = Arr::only($rules, []);
        }
        if ($this->isMethod('post')) {
            $rules = $this->makeRules('demo', $rules);
        }
        if ($this->isMethod('put')) {
            $rules = $this->makeRules('demo', Arr::only($rules, $keys));
        }
        return $rules;
    }

    public function messages()
    {
        return [];
    }

    public function attributes()
    {
        $systemModel = app(SystemModel::class);
        $demo = app(Demo::class);
        return $systemModel->fieldAttributes($demo->getTable());
    }
}
